package com.pan.sample.model;

import android.util.Base64;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

/**
 * @author zhongjh
 */
public class SysConfig {

    private String serverIp;

    private String serverPort;

    private String serverUrlFormat;

    private String broadcastServerIp;

    private String broadcastServerPort;

    private String server510Ip;

    private String server510Port;

    private String isWindow;

    private String area;

    private String assessmentItems;

    private String downloadTime;

    private String license;

    private String deviceId;

    private String satyTime;

    private String layout;

    private String pageSize;

    private String pageTime;

    private String pollingInterval;

    private String terminalName;

    private String branchNo;

    private String isConnectStateShow;

    private String type;

    private String leisureTime;

    private String operatorPort;

    private String startX;

    private String startY;

    private String operatorWidth;

    private String operatorHeight;

    private String presonNum;

    private String presonName;

    private String serialPort;

    private String serialPortSwitch;

    private String isLock;

    private String buttonCount;

    private String infraredSwitch;

    private String gpioAdd;

    private String infraredTime;

    private String infraredLevel;

    private String ledType;

    private String isAck;

    private String ledAdd;

    private String dualSwitch;

    private String usbCameraId;

    private String serialPortLogSwitch;

    private String serialPortAddFilter;

    private String winInfoTime;

    private String goodTimeout;

    private String videoVol;

    private String callVol;


    private String advertisingTime;


   /* private String checkWeeks;

    private String time_open;

    private String time_shutdown;
*/


    public String getServerIp() {
        return serverIp;
    }

    public void setServerIp(String serverIp) {
        this.serverIp = serverIp;
    }

    public String getServerPort() {
        return serverPort;
    }

    public void setServerPort(String serverPort) {
        this.serverPort = serverPort;
    }

    public String getServerUrlFormat() {
        return serverUrlFormat;
    }

    public void setServerUrlFormat(String serverUrlFormat) {
        this.serverUrlFormat = serverUrlFormat;
    }


    public String getBroadcastServerIp() {
        return broadcastServerIp;
    }

    public void setBroadcastServerIp(String broadcastServerIp) {
        this.broadcastServerIp = broadcastServerIp;
    }

    public String getBroadcastServerPort() {
        return broadcastServerPort;
    }

    public void setBroadcastServerPort(String broadcastServerPort) {
        this.broadcastServerPort = broadcastServerPort;
    }

    public String getServer510Ip() {
        return server510Ip;
    }

    public void setServer510Ip(String server510Ip) {
        this.server510Ip = server510Ip;
    }

    public String getServer510Port() {
        return server510Port;
    }

    public void setServer510Port(String server510Port) {
        this.server510Port = server510Port;
    }

    public String getIsWindow() {
        return isWindow;
    }

    public void setIsWindow(String isWindow) {
        this.isWindow = isWindow;
    }

    public String getAssessmentItems() {
        return assessmentItems;
    }

    public void setAssessmentItems(String assessmentItems) {
        this.assessmentItems = assessmentItems;
    }

    public String getDownloadTime() {
        return downloadTime;
    }

    public void setDownloadTime(String downloadTime) {
        this.downloadTime = downloadTime;
    }

    public String getLicense() {
        if (license != null && license.length() > 0) {
            return decryptEcb(license, AES_KEY);
        } else {
            return license;
        }
    }

    public void setLicense(String license) {
        if (license != null && license.length() > 0) {
            this.license = encryptEcb(license, AES_KEY);
        } else {
            this.license = license;
        }
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getSatyTime() {
        return satyTime;
    }

    public void setSatyTime(String satyTime) {
        this.satyTime = satyTime;
    }

    public String getLayout() {
        return layout;
    }

    public void setLayout(String layout) {
        this.layout = layout;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public String getPageSize() {
        return pageSize;
    }

    public void setPageSize(String pageSize) {
        this.pageSize = pageSize;
    }


    public String getPageTime() {
        return pageTime;
    }

    public void setPageTime(String pageTime) {
        this.pageTime = pageTime;
    }


    public String getPollingInterval() {
        return pollingInterval;
    }

    public void setPollingInterval(String pollingInterval) {
        this.pollingInterval = pollingInterval;
    }

    public String getTerminalName() {
        return terminalName;
    }

    public void setTerminalName(String terminalName) {
        this.terminalName = terminalName;
    }

    public String getIsConnectStateShow() {
        return isConnectStateShow;
    }

    public void setIsConnectStateShow(String isConnectStateShow) {
        this.isConnectStateShow = isConnectStateShow;
    }

    public String getType() {
        return type;
    }

    public void setType(String terminalType) {
        this.type = terminalType;
    }

    public String getOperatorPort() {
        return operatorPort;
    }

    public void setOperatorPort(String operatorPort) {
        this.operatorPort = operatorPort;
    }

    public String getLeisureTime() {
        return leisureTime;
    }

    public void setLeisureTime(String leisureTime) {
        this.leisureTime = leisureTime;
    }

    public String getStartX() {
        return startX;
    }

    public void setStartX(String startX) {
        this.startX = startX;
    }

    public String getStartY() {
        return startY;
    }

    public void setStartY(String startY) {
        this.startY = startY;
    }

    public String getOperatorWidth() {
        return operatorWidth;
    }

    public void setOperatorWidth(String operatorWidth) {
        this.operatorWidth = operatorWidth;
    }

    public String getOperatorHeight() {
        return operatorHeight;
    }

    public void setOperatorHeight(String operatorHeight) {
        this.operatorHeight = operatorHeight;
    }

    public String getPresonNum() {
        return presonNum;
    }

    public void setPresonNum(String presonNum) {
        this.presonNum = presonNum;
    }

    public String getPresonName() {
        return presonName;
    }

    public void setPresonName(String presonName) {
        this.presonName = presonName;
    }

    public String getIsLock() {
        return isLock;
    }

    public void setIsLock(String isLock) {
        this.isLock = isLock;
    }

    public void setSerialPort(String serialPort) {
        this.serialPort = serialPort;
    }

    public String getSerialPortSwitch() {
        return serialPortSwitch;
    }

    public void setSerialPortSwitch(String serialPortSwitch) {
        this.serialPortSwitch = serialPortSwitch;
    }

    public String getSerialPort() {
        return serialPort;
    }

    public String getButtonCount() {
        return buttonCount;
    }

    public void setButtonCount(String buttonCount) {
        this.buttonCount = buttonCount;
    }

    public String getInfraredSwitch() {
        return infraredSwitch;
    }

    public void setInfraredSwitch(String infraredSwitch) {
        this.infraredSwitch = infraredSwitch;
    }

    public String getGpioAdd() {
        return gpioAdd;
    }

    public void setGpioAdd(String gpioAdd) {
        this.gpioAdd = gpioAdd;
    }

    public String getInfraredTime() {
        return infraredTime;
    }

    public void setInfraredTime(String infraredTime) {
        this.infraredTime = infraredTime;
    }

    public String getInfraredLevel() {
        return infraredLevel;
    }

    public void setInfraredLevel(String infraredLevel) {
        this.infraredLevel = infraredLevel;
    }

    public String getLedType() {
        return ledType;
    }

    public void setLedType(String ledType) {
        this.ledType = ledType;
    }

    public String getIsAck() {
        return isAck;
    }

    public void setIsAck(String isAck) {
        this.isAck = isAck;
    }

    public String getLedAdd() {
        return ledAdd;
    }

    public void setLedAdd(String ledAdd) {
        this.ledAdd = ledAdd;
    }

    public String getDualSwitch() {
        return dualSwitch;
    }

    public void setDualSwitch(String dualSwitch) {
        this.dualSwitch = dualSwitch;
    }

    public String getUsbCameraId() {
        return usbCameraId;
    }

    public void setUsbCameraId(String usbCameraId) {
        this.usbCameraId = usbCameraId;
    }

    public String getSerialPortLogSwitch() {
        return serialPortLogSwitch;
    }

    public void setSerialPortLogSwitch(String serialPortLogSwitch) {
        this.serialPortLogSwitch = serialPortLogSwitch;
    }

    public String getSerialPortAddFilter() {
        return serialPortAddFilter;
    }

    public void setSerialPortAddFilter(String serialPortAddFilter) {
        this.serialPortAddFilter = serialPortAddFilter;
    }

    public String getWinInfoTime() {
        return winInfoTime;
    }

    public void setWinInfoTime(String winInfoTime) {
        this.winInfoTime = winInfoTime;
    }

    public String getGoodTimeout() {
        return goodTimeout;
    }

    public void setGoodTimeout(String goodTimeout) {
        this.goodTimeout = goodTimeout;
    }

    public String getBranchNo() {
        return branchNo;
    }

    public void setBranchNo(String branchNo) {
        this.branchNo = branchNo;
    }

    public String getVideoVol() {
        return videoVol;
    }

    public void setVideoVol(String videoVol) {
        this.videoVol = videoVol;
    }

    public String getCallVol() {
        return callVol;
    }

    public void setCallVol(String callVol) {
        this.callVol = callVol;
    }

    public String getAdvertisingTime() {
        return advertisingTime;
    }

    public void setAdvertisingTime(String advertisingTime) {
        this.advertisingTime = advertisingTime;
    }

    private static final String AES_KEY = "wY8wmChTYPQpq8HO";

    private static String encryptEcb(String message, String key) {
        final String cipherMode = "AES/ECB/PKCS5Padding";
        final String charsetName = "UTF-8";
        try {
            byte[] content = new byte[0];
            content = message.getBytes(charsetName);
            //
            byte[] keyByte = key.getBytes(charsetName);
            SecretKeySpec keySpec = new SecretKeySpec(keyByte, "AES");

            Cipher cipher = Cipher.getInstance(cipherMode);
            cipher.init(Cipher.ENCRYPT_MODE, keySpec);
            byte[] data = cipher.doFinal(content);
            return Base64.encodeToString(data, Base64.DEFAULT);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private static String decryptEcb(String messageBase64, String key) {
        final String cipherMode = "AES/ECB/PKCS5Padding";
        final String charsetName = "UTF-8";
        try {
            byte[] messageByte = Base64.decode(messageBase64, Base64.DEFAULT);

            //
            byte[] keyByte = key.getBytes(charsetName);
            SecretKeySpec keySpec = new SecretKeySpec(keyByte, "AES");

            Cipher cipher = Cipher.getInstance(cipherMode);
            cipher.init(Cipher.DECRYPT_MODE, keySpec);
            byte[] content = cipher.doFinal(messageByte);
            return new String(content, charsetName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
